// permutations.cpp : Defines the entry point for the console application.
//

#include "TestUtils.h"
#include "PermutationsUnitTests.h"
#include "Permutations.h"
#include "Permutation.h"
#include "stdafx.h"
#include "XmlDefinitions.h"
#include "./Markup/Markup.h"
#include <iostream>
#include <string>
#include <time.h>
using namespace std;

// Create filename from current timestamp
string GetCurrentFileName()
{
	time_t rawtime;
	time(&rawtime);
    struct tm * timeinfo;
	timeinfo = localtime(&rawtime);
	char buffer[18];
	strftime (buffer,18,"%Y%m%d_%H%M.xml",timeinfo);
	string filename(buffer);

	return filename;
}

int _tmain(int argc, _TCHAR* argv[])
{
	if (argc < 2)
	{
		cout << "Usage: permutations.exe <parameters filename>" << endl;
		return -1;
	}

	CMarkup xmlFile;
	if (xmlFile.Load(argv[1]) == false)
	{
		cout << "Could not load file " << argv[1] << endl;
		return NULL;
	}

	Permutations *permutations = Permutations::CreatePermutationsObject(xmlFile);

	if (NULL == permutations)
	{
		cout << "Error, exiting... " << endl;
		return -1;
	}
	
	permutations->Run(GetCurrentFileName());
	if (_DEBUG)
	{
		permutations->SaveGroups("groups.xml");
	}
	 
	delete permutations;

	if (_DEBUG)
	{
		RunTests();
	}

	return 0;
}

